<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="../templates/principal.xhtml">

    <ui:define name="content" id="content">
        <h1 class="title ui-widget-header ui-corner-all">Bem Vindo ao Cadastro de Empresa</h1>

        <h:form id="frmEmpresa">


            <p:dataTable id="tabEmpresa" widgetVar="wtabEmpresa" var="empresa" value="#{empresaBean.lazyModel}" paginator="true" rows="12" lazy="true"
                         emptyMessage="Nenhum Registro Retornado ..."
                         selection="#{empresaBean.selectedEmpresa}" selectionMode="single"
                         onRowSelectComplete="empresaDialog.show()" onRowSelectUpdate="display">

                <f:facet name="header">
                    Selecione uma linha e clique para Manutenção
                </f:facet>

                <p:column headerText="Descrição">
                    <h:outputText value="#{empresa.nomEmpresa}" />
                </p:column>

                <p:column headerText="Total de Ações" style="text-align: right">
                    <h:outputText value="#{empresa.qdeTotal}">
                        <f:convertNumber locale="pt_BR" pattern="###,###,###,##0.00" minFractionDigits="0" />
                    </h:outputText>
                </p:column>
            </p:dataTable>

            <p:dialog id="dialog" header="Detalhes Empresa" widgetVar="empresaDialog" resizable="true"
                      width="900" showEffect="explode" hideEffect="explode">

                <h:panelGrid id="display" columns="2" style="margin-bottom:50px" cellpadding="5">
                    <h:outputText value="Razão Social:" />
                    <p:inputText id="Descricao" value="#{empresaBean.selectedEmpresa.nomEmpresa}" required="true" style="width:600px; font-weight:bold;" />

                    <h:outputText value="Total de Ações:" />
                    <p:inputText id="qdeTotal" widgetVar="qdeTotal" value="#{empresaBean.selectedEmpresa.qdeTotal}" 
                                 style="width:200px; font-weight:bold; text-align: right;"
                                 onkeyup="javascript:maskIt(this,event,'###.###.###.###',true)">
                        <f:convertNumber locale="pt_BR" pattern="###,###,##0.00" minFractionDigits="0" />
                    </p:inputText>
                    
                    <h:outputText value="Nº. da Ultima Transferência:" />
                    <p:inputText id="numTransferencia" widgetVar="numTransferencia" value="#{empresaBean.selectedEmpresa.numTransferencia}" 
                                 style="width:200px; font-weight:bold; text-align: right;"
                                 onkeyup="javascript:maskIt(this,event,'###.###.###.###',true)">
                        <f:convertNumber locale="pt_BR" pattern="###,###,###,##0.00" minFractionDigits="0" />
                    </p:inputText>
                    
                    <h:outputText value="Nº. do Ultimo Certificado:" />
                    <p:inputText id="numCertificado" widgetVar="numCertificado" value="#{empresaBean.selectedEmpresa.numCertificado}" 
                                 style="width:200px; font-weight:bold; text-align: right;"
                                 onkeyup="javascript:maskIt(this,event,'###.###.###.###',true)">
                        <f:convertNumber locale="pt_BR" pattern="###,###,###,##0.00" minFractionDigits="0" />
                    </p:inputText>
                </h:panelGrid>
                <br />
                <p:commandButton value="Gravar" update="messages,tabEmpresa,display"
                                 actionListener="#{empresaBean.alterar}" oncomplete="empresaDialog.hide()" />
            </p:dialog>
        </h:form>
    </ui:define>
</ui:composition>
